import * as types from "./mutation-type";

const mutations = {
  // 改变loading状态
  [types.SET_LOADING](state, status) {
    state.isLoading = status;
  },
  // 账户余额
  [types.SET_BALANCE](state, data) {
    state.balance = data;
    localStorage.setItem("fn_balance", JSON.stringify(data));
  },
  // 是否登录
  [types.SET_LOGININFO](state, user) {
    if (user) {
      state.userInfo = user;
      localStorage.setItem("fn_token", user.token);
      localStorage.setItem("fn_userInfo", JSON.stringify(user));
    } else if (user == null) {
      state.userInfo = null;
      localStorage.setItem("fn_token", "");
      localStorage.setItem("fn_userInfo", null);
    }
  },
  // 改变当前Dialog
  [types.SET_CURRENT_DIALOG](state, data) {
    if (data) {
      state.currentDialog = {
        ...data,
        showDialog: true,
      };
    } else {
      state.currentDialog = {
        showDialog: false,
      };
    }
  },
};

export default mutations;
